package com.xaut.outpatientsystem.medicinalManagement.util;

import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class ExcelToPDFUtil {

    /**
     * Excel文件转Pdf.
     * @param excelPath Excel文件路径.
     * @param pdfPath Pdf文件路径.
     * @throws Exception .
     */
    public static void excelToPdf(String excelPath, String pdfPath) throws Exception {
        // 加载Excel文档.
        Workbook wb = new Workbook();
        wb.loadFromFile(excelPath);
        // 调用方法保存为PDF格式.
        wb.saveToFile(pdfPath, FileFormat.PDF);
    }

    /**
     * Excel文件转Pdf.
     * @param excelPath Excel文件路径.
     * @param pdfPath Pdf文件路径.
     * @param sheetIndex sheet页序号.
     * @throws Exception .
     */
    public static void excelToPdf(String excelPath, String pdfPath, int sheetIndex) throws Exception {
        // 加载Excel文档.
        Workbook wb = new Workbook();
        wb.loadFromFile(excelPath);

        Worksheet sheet = wb.getWorksheets().get(sheetIndex);
        // 调用方法保存为PDF格式.
        wb.saveToFile(pdfPath, FileFormat.PDF);
    }

}
